package com.xblog;

import com.jfinal.config.*;
import com.jfinal.core.JFinal;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;
import com.jfinal.template.Engine;
import com.xblog.controller.BlogController;
import com.xblog.controller.IndexController;
import com.xblog.model.Blog;

/**
 * Created by leo on 2017-09-13.
 */
public class CommonConfig extends JFinalConfig {
    public static void main(String[] args) {

        JFinal.start("WebRoot", 80, "/" );


    }
    @Override
    public void configConstant(Constants me) {
        PropKit.use("config.properties");
        me.setViewType(ViewType.JSP);//设置视图模板的基本路径
        me.setDevMode(true);//设置开发模式
        me.setBaseUploadPath("WebRoot/file");
    }

    @Override
    public void configRoute(Routes me) {
        me.add("/", IndexController.class, "/index");
        me.add("/blog", BlogController.class);//建立访问路由


    }

    @Override
    public void configEngine(Engine me) {

    }

    @Override
    public void configPlugin(Plugins me) {
        //配置C3p0数据库连续插件
        C3p0Plugin c3p0Plugin=new C3p0Plugin(PropKit.get("jdbcUrl"),PropKit.get("user"),PropKit.get("password").trim());
        me.add(c3p0Plugin);
        //配置ActiveRecord插件
        ActiveRecordPlugin arp=new ActiveRecordPlugin(c3p0Plugin);
        me.add(arp);
        arp.setShowSql(true);
        //手动去指定表名和主键，如果没有手动指定主键，将默认id为主键
        arp.addMapping("blog", "id", Blog.class);
        //arp.addMapping("blog",Blog.class);
    }

    @Override
    public void configInterceptor(Interceptors me) {

    }

    @Override
    public void configHandler(Handlers me) {

    }
}
